<?php
require_once("lib/file.lib.php");
function loadConfigs($file) {
	$vars=array();
	foreach (listFiles($file) as $elt) {
		if ( preg_match ( '/([^.]+)\/(.+?)\.([^.]+?)$/', $elt, $matches)) {
			if ($matches[3]== "ini") {
				$vars[$matches[2]]=parse_ini_file( $elt, true );		
			}
			if ($matches[3]== "yaml") {
				require_once('../lib/yaml.lib.php');
				$vars[$matches[2]] = Spyc::YAMLLoad($elt);
			}
			if ($matches[3]== "xml") {
				require_once('../lib/xml.lib.php');
				$vars[$matches[2]] = xmlfile2assoc($elt);
			}
			if ($matches[3]== "php") {
				unset($config);
				eval(file_get_contents($elt));
				$vars[$matches[2]] = $config;
			}				
			if ($matches[3]== "conf") {
				foreach ( explode ("\n", file_get_contents($elt)) as $line) {
					# Comment?
					if ( ! preg_match("/#.*/", $line) ) {
						# Contains non-whitespace?
						if ( preg_match("/\S/", $line) ) {
							list( $key, $value ) = explode( "=", trim( $line ), 2);
							$vars[$matches[2]][$key] = $value;
						}
					}
				}
			}
		}
	}	
	return($vars);
}
?>
